package com.linkage.educloud.ah.bean;

import com.linkage.educloud.ah.data.CursorHelper;
import com.linkage.educloud.ah.data.Ws;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Child implements Serializable {

    private static final long serialVersionUID = 100125L;
    private long id;
    private String name;
    private String parentId;// 父母id
    private String classname;// 班级名称
    private String classid;// 班级id
    private String school;// 学校名称
    private String avatar;// 学生头像
    private String remoteid;// 老平台班级id，用于班级群聊，班级空间
    private int gradeid;
    private String gradename;
    private int defaultChild;

    public static List<Child> parseFromJsonForLogin(JSONArray jsonArray) {
        List<Child> clazzs = new ArrayList<Child>();
        if (jsonArray != null && jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                Child clazz = parseFromJsonForLogin(jsonArray
                        .optJSONObject(i));
                if (clazz != null)
                    clazzs.add(clazz);
            }
        }
        return clazzs;
    }

    public static Child parseFromJsonForLogin(JSONObject jsonObj) {
        Child child = new Child();
        child.setId(jsonObj.optLong("id"));
        child.setName(jsonObj.optString("name"));
        child.setAvatar(jsonObj.optString("cavatar"));
        child.setSchool(jsonObj.optString("schoolname"));
        child.setClassname(jsonObj.optString("classname"));
        child.setClassid(jsonObj.optString("classId"));
        child.setGradeid(jsonObj.optInt("gradeid"));
        child.setGradename(jsonObj.optString("gradename"));
        child.setRemoteid(jsonObj.optString("remoteId"));
        return child;
    }

    public String getRemoteid() {
        return remoteid;
    }

    public void setRemoteid(String remoteid) {
        this.remoteid = remoteid;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getDefaultChild() {
        return defaultChild;
    }

    public void setDefaultChild(int defaultChild) {
        this.defaultChild = defaultChild;
    }

    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String cavatar) {
        this.avatar = cavatar;
    }

    public String getClassid() {
        return classid;
    }

    public void setClassid(String classid) {
        this.classid = classid;
    }

    public int getGradeid() {
        return gradeid;
    }

    public void setGradeid(int gradeid) {
        this.gradeid = gradeid;
    }

    public String getGradename() {
        return gradename;
    }

    public void setGradename(String gradename) {
        this.gradename = gradename;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public static Child fromCursor(CursorHelper cursorHelper) {
        Child child = new Child();
        child.id = cursorHelper.getLong(Ws.ChildTable._ID);
        child.name = cursorHelper.getString(Ws.ChildTable.NAME);
        child.parentId = cursorHelper.getString(Ws.ChildTable.PARENTID);
        child.classname = cursorHelper.getString(Ws.ChildTable.CLASSNAME);
        child.classid = cursorHelper.getString(Ws.ChildTable.CLASSID);
        child.school = cursorHelper.getString(Ws.ChildTable.SCHOOL);
        child.avatar = cursorHelper.getString(Ws.ChildTable.AVATAR);
        child.gradeid = cursorHelper.getInt(Ws.ChildTable.GRADEID);
        child.gradename = cursorHelper.getString(Ws.ChildTable.GRADENAME);
        child.defaultChild = cursorHelper.getInt(Ws.ChildTable.DEFAULTCHILD);
        child.remoteid = cursorHelper.getString(Ws.ChildTable.REMOTEID);
        return child;
    }
}
